package com.study.common

import android.text.Html
import android.text.Spanned
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer

object MDParser {

    private val htmlRender =  HtmlRenderer.builder().build()
    private val parser = Parser.Builder().build()

    private fun parserMdToHtml(markdownStr : String) : String{
        return htmlRender.render(parser.parse(markdownStr))
    }

    fun toSpanned(markdownStr: String) : Spanned{
        return Html.fromHtml(parserMdToHtml(markdownStr),Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM)
    }
}